org 0x0000
	
	ori	$sp, $0, 0x6000 #new stack location
	ori	$1, $0, sortdata
	ori     $2, $2, sorted1 #pointer
	ori 	$3, $0, 100 #count max
	
	ori	$5, $0, 1 #our target
	ori 	$6, $0, 0 #count of stored values (pointer math helper)
	ori 	$8, $0, 400
l1outer:
	ori	$4, $0, 0 #array count #reset i = 0

l1top:
	addu $7, $1, $4
	lw $7, 0($7) #this is sortdata[i]
	bne $7, $5, l1cleanup
	sw $7, 0($2)
	addiu $2, $2, 4 #inc sorted pointer	
l1cleanup:
	addiu $4, $4, 4 #i++ in the array
	bne $4, $8, l1top

l1outercleanup:
	beq $5, $3, l1end
        addiu $5, $5, 1 #inc target
	j l1outer

l1end:
	halt

org 0x200
	
	ori	$sp, $0, 0x7000 #new stack location
	ori	$1, $0, sortdata
	ori     $2, $2, sorted2 #pointer
	ori 	$3, $0, 1 #count min
	
	ori	$5, $0, 100 #our target
	ori 	$6, $0, 0 #count of stored values (pointer math helper)
	ori 	$8, $0, 400
l2outer:
	ori	$4, $0, 0 #array count #reset i = 0

l2top:
	addu $7, $1, $4
	lw $7, 0($7) #this is sortdata[i]
	bne $7, $5, l2cleanup
	sw $7, 0($2)
	sll $0, $0, 0 #nop
	addiu $2, $2, 4 #inc sorted pointer	
l2cleanup:
	addiu $4, $4, 4 #i++ in the array
	bne $4, $8, l2top

l2outercleanup:
	beq $5, $3, l2end
        addiu $5, $5, -1 #inc target
	j l2outer

l2end:
	halt


	
org 0x2000


sortdata:

#1 - 25	
cfw 0x0002
cfw 0x000F
cfw 0x005b
cfw 0x0003
cfw 0x0007
cfw 0x0004
cfw 0x0050
cfw 0x000E
cfw 0x0017
cfw 0x0013
cfw 0x0010
cfw 0x0008
cfw 0x0006
cfw 0x0015
cfw 0x0005
cfw 0x0011
cfw 0x000D
cfw 0x0014
cfw 0x0016
cfw 0x001A
cfw 0x0032
cfw 0x001B
cfw 0x001C
cfw 0x001E
cfw 0x0028
cfw 0x001F
cfw 0x0020
cfw 0x0021
cfw 0x0022
cfw 0x0023
cfw 0x0025
cfw 0x004a
cfw 0x0026
cfw 0x0027
cfw 0x003
cfw 0x0029
cfw 0x002A
cfw 0x0036
cfw 0x002b
cfw 0x002c
cfw 0x003e
cfw 0x005c
cfw 0x001D
cfw 0x002e
cfw 0x0019
cfw 0x0001
cfw 0x004c
cfw 0x0009
cfw 0x002f
cfw 0x0031
cfw 0x0033
cfw 0x0048
cfw 0x0034
cfw 0x0035
cfw 0x0037
cfw 0x0024
cfw 0x0038
cfw 0x0039
cfw 0x0064
cfw 0x003a
cfw 0x003b
cfw 0x003d
cfw 0x003f
cfw 0x0040
cfw 0x0030
cfw 0x0041
cfw 0x0043
cfw 0x0044
cfw 0x0045
cfw 0x002d
cfw 0x0046
cfw 0x0047
cfw 0x0049
cfw 0x004b
cfw 0x004d
cfw 0x004e
cfw 0x004f
cfw 0x0042
cfw 0x0051
cfw 0x005f
cfw 0x0052
cfw 0x0054
cfw 0x0055
cfw 0x0063
cfw 0x0056
cfw 0x0057
cfw 0x000A
cfw 0x0012
cfw 0x000B
cfw 0x0018
cfw 0x000C
cfw 0x0058
cfw 0x0059
cfw 0x005a
cfw 0x005d
cfw 0x005e
cfw 0x0060
cfw 0x0061
cfw 0x0062
cfw 0x0053






org 0x02500
sorted1:	
cfw 0x0000
	
org 0x03000
sorted2:
cfw 0x0000
#so the next 400 mem addresses will be the sorted result array
